package com.ruoyi.web.controller.system;

import java.text.ParseException;
import java.util.List;

import com.ruoyi.system.domain.WarLev;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MouthMessage;
import com.ruoyi.system.service.IMouthMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月度信息Controller
 *
 * @author ruoyi
 * @date 2021-01-07
 */
@RestController
@RequestMapping("/system/message/month")
public class MouthMessageController extends BaseController {
    @Autowired
    private IMouthMessageService mouthMessageService;

    //月度信息回显
    @GetMapping("/list")
    public TableDataInfo list(MouthMessage mouthMessage) {
        startPage();
        List<MouthMessage> list = mouthMessageService.selectMouthMessageList(mouthMessage.getProId());
        return getDataTable(list);
    }

    //月度信息新增
    //@PreAuthorize("@ss.hasPermi('system:message:add')")
    @Log(title = "新增月度信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MouthMessage mouthMessage) throws ParseException {
        if(mouthMessageService.insertMouthMessage(mouthMessage)==1){
            return AjaxResult.success("新增成功");
        }else {
            return AjaxResult.error(mouthMessage.getMouYearMouth()+"月的月度信息已录入无法重复录入");
        }
    }

    //删除月份信息
    // @PreAuthorize("@ss.hasPermi('system:message:remove')")
    @Log(title = "删除月度信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mouId}")
    public AjaxResult remove(@PathVariable Long mouId) {
        return toAjax(mouthMessageService.deleteMouthMessageById(mouId));
    }


    //修改月份
    //@PreAuthorize("@ss.hasPermi('system:message:edit')")
    @Log(title = "修改月度信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MouthMessage mouthMessage) throws ParseException {
        if(mouthMessageService.updateMouthMessage(mouthMessage)==1){
            return AjaxResult.success("修改成功");
        }else {
            return AjaxResult.error(mouthMessage.getMouYearMouth()+"月的月度信息已录入无法修改");
        }
    }

    //预警等级
    @PostMapping("/getWarLev")
    public TableDataInfo getWarLev() {
        List<WarLev> list = mouthMessageService.selectWarLev();
        return getDataTable(list);
    }

//    /**
//     * 导出月度信息列表
//     */
//    @PreAuthorize("@ss.hasPermi('system:message:export')")
//    @Log(title = "月度信息", businessType = BusinessType.EXPORT)
//    @GetMapping("/export")
//    public AjaxResult export(MouthMessage mouthMessage)
//    {
//        List<MouthMessage> list = mouthMessageService.selectMouthMessageList(mouthMessage);
//        ExcelUtil<MouthMessage> util = new ExcelUtil<MouthMessage>(MouthMessage.class);
//        return util.exportExcel(list, "message");
//    }


}
